﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

using EnvironmentalMonitor.Support.Module;

namespace EnvironmentalMonitor.WebApplication.Abstract
{
    /// <summary>
    /// 抽象列表Json数据页面类
    /// </summary>
    public abstract class AbstractListJson : EnvironmentalMonitor.WebApplication.Abstract.AbstractSecurityPage
    {
        private int _PageValue;
        /// <summary>
        /// 页码
        /// </summary>
        public int PageValue
        {
            get
            {
                return this._PageValue;
            }
            set
            {
                this._PageValue = value;
            }
        }

        private int _RowsValue;
        /// <summary>
        /// 每页行数
        /// </summary>
        public int RowsValue
        {
            get
            {
                return this._RowsValue;
            }
            set
            {
                this._RowsValue = value;
            }
        }

        private ListJsonData _ListJsonData;
        /// <summary>
        /// 列表Json数据
        /// </summary>
        public ListJsonData ListJsonData
        {
            get
            {
                return this._ListJsonData;
            }
            set
            {
                this._ListJsonData = value;
            }
        }

        /// <summary>
        /// Json数据
        /// </summary>
        /// <returns>Json数据</returns>
        public string Json()
        {
            string result = string.Empty;

            result = JsonConvert.SerializeObject(this.ListJsonData);

            return result;
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            const string PAGE = "page";
            const string ROWS = "rows";

            string pageText = this.ParameterString(PAGE);
            if (!string.IsNullOrEmpty(pageText))
            {
                try
                {
                    this.PageValue = int.Parse(pageText);
                }
                catch (Exception exception)
                {
                    EnvironmentalMonitor.Support.Resource.Variable.Logger.Log(exception);
                }
                finally
                {
                }
            }

            string rowsText = this.ParameterString(ROWS);
            if (!string.IsNullOrEmpty(rowsText))
            {
                try
                {
                    this.RowsValue = int.Parse(rowsText);
                }
                catch (Exception exception)
                {
                    EnvironmentalMonitor.Support.Resource.Variable.Logger.Log(exception);
                }
                finally
                {
                }
            }
        }
    }
}